package com.loong.controller;

import com.loong.dto.EmpDTO;
import com.loong.entity.Emp;
import com.loong.result.PageBean;
import com.loong.result.Result;
import com.loong.service.EmpService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.List;

@RestController
@RequestMapping("/emps")
public class EmpController {
    @Autowired
    private EmpService empService;

    @GetMapping
    public Result<PageBean> list(EmpDTO empDTO) {
        return Result.success(empService.list(empDTO));
    }

    @GetMapping("/list")
    public Result<List<Emp>> listAll() {
        return Result.success(empService.listAll());
    }

    @GetMapping("/{id}")
    public Result<Emp> get(@PathVariable Integer id) {
        return Result.success(empService.get(id));
    }

    @DeleteMapping
    public Result<?> delete(@RequestParam List<Integer> ids) {
        empService.delete(ids);
        return Result.success();
    }

    @PostMapping
    public Result<?> insert(@RequestBody Emp emp) {
        empService.insert(emp);
        return Result.success();
    }

    @PutMapping
    public Result<?> update(@RequestBody Emp emp) {
        empService.update(emp);
        return Result.success();
    }
}
